using BootstrapBlazorApp.Server.LLMs.api;
using BootstrapBlazorApp.Server.LLMs.chain;

namespace BootstrapBlazorApp.Server.LLMs.parser;

public class StringOutPutParser : IBaseOutPutParser
{
    public async Task<ChainContext> InvokeAsync(ChainContext input)
    {
        input.OutPutContent = Parser(input);
        return await Task.FromResult(input);
    }

    public async IAsyncEnumerable<ChainContext> InvokeStreamAsync(ChainContext input)
    {
        foreach (var c in input.IncrementalOutput)
        {
            input.OutPutContent = c.ToString();
           yield return await Task.FromResult(input);
        }
        
    }

    
    public string GetInstruction()
    {
        return "请根据用户输入生成回复";
    }

    private static string Parser(ChainContext input)
    {
        return input.GetLastMessage().Content;
    }
}
